package com.maxwell.googleplay.factory;

import java.util.HashMap;
import java.util.Map;

import com.maxwell.googleplay.base.BaseFragment;
import com.maxwell.googleplay.fragment.AppFragment;
import com.maxwell.googleplay.fragment.CategoryFragment;
import com.maxwell.googleplay.fragment.GameFragment;
import com.maxwell.googleplay.fragment.HomeFragment;
import com.maxwell.googleplay.fragment.HotFragment;
import com.maxwell.googleplay.fragment.RecommendFragment;
import com.maxwell.googleplay.fragment.SubjectFragment;

import android.support.v4.app.Fragment;
import android.support.v4.util.SparseArrayCompat;

/**
 * @author yue
 * @创建时间 2016-3-30上午9:14:31
 * @描述 TODO
 * 
 */
public class FragmentFactory {

	public static final int FRAGMENT_HOME = 0;
	public static final int FRAGMENT_APP = 1;
	public static final int FRAGMENT_GAME = 2;
	public static final int FRAGMENT_SUBJECT = 3;
	public static final int FRAGMENT_RECOMMEND = 4;
	public static final int FRAGMENT_CATEGORY = 5;
	public static final int FRAGMENT_HOT = 6;
	
	static SparseArrayCompat<BaseFragment> cachesFragment = new SparseArrayCompat<BaseFragment>();

	public static BaseFragment getFragment(int position) {
	
		BaseFragment fragment = null;
		//如果缓存里面有，直接从缓存里面取
		BaseFragment tempFragment = cachesFragment.get(position);
		if(tempFragment != null){
			fragment = tempFragment;
			return fragment;
		}
		
		switch (position) {
		case FRAGMENT_HOME:
			fragment  = new HomeFragment();
			
			break;
		case FRAGMENT_APP:
			fragment  = new AppFragment();
			break;
		case FRAGMENT_GAME:
			fragment  = new GameFragment();
			break;
		case FRAGMENT_SUBJECT:
			fragment  = new SubjectFragment();
			break;
		case FRAGMENT_RECOMMEND:
			fragment  = new RecommendFragment();
			break;
		case FRAGMENT_CATEGORY:
			fragment  = new CategoryFragment();
			break;
		case FRAGMENT_HOT:
			fragment  = new HotFragment();
			break;
		default:
			break;
		}
		
		//保存对应的fragment
		cachesFragment.put(position, fragment);
		return fragment;
	}
}
